package service.serviceimpl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import dao.GoodsDao;
import dao.GoodstypeDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import pojo.Goods;
import pojo.GoodsType;
import pojo.User;
import service.GoodsService;

import java.util.List;
@Service
public class GoodsServiceimpl implements GoodsService {

    @Autowired
    GoodsDao goodsDao;
    @Autowired
    GoodstypeDao goodstypeDao;
    @Override
    public PageInfo<Goods> selectAll(Integer pageNum, Integer pageSize,int id) {
        PageHelper.startPage(pageNum,pageSize);

        List<Goods> goods = goodsDao.selectAll(id);
        System.out.println(goods);

        PageInfo<Goods> pageInfo = new PageInfo<>(goods);

        return pageInfo;

    }

    @Override
    public Goods selectOne(int id) {
         Goods goods = goodsDao.selectOne(id);
         int typeId = goods.getTypeid();
        GoodsType goodsType = goodstypeDao.selectOne(typeId);
         goods.setGoodsType(goodsType);
         return goods;
    }

    @Override
    public void deleteOne(int goodsId, int userId) {
        goodsDao.deleteOne(goodsId,userId);
    }
}
